package cn.gson.crmdemo.controller.finance;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.Emp;
import cn.gson.crmdemo.model.service.TkjlService;
import cn.gson.crmdemo.model.vo.RegressionInvoiceReturnsVo;
import cn.gson.crmdemo.model.vo.TkjlVo;

@Controller
public class TkjlController {
	@Autowired
	TkjlService ts;
	public Map<String,Object> yy(JSONArray selecthk,Page page) {
		Map<String, Object> map=new HashMap<String,Object>();
		map.put("list",selecthk);
		map.put("total",page.getTotal());
		return map;
	}
	//查询退货单
			@RequestMapping("tkjl")
			@ResponseBody
			public Map<String,Object>fkfp(Integer pageNum,Integer pasgeSize,String rrDate){
				//分页
				Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
				//查询数据
				JSONArray selectfkfp=ts.selecttkjl(rrDate);
				//创建Map集合
				return this.yy(selectfkfp, page);
				
			}
		//退款记录
			@RequestMapping("addtkjloi")
			public String addtkjl(TkjlVo to,HttpServletRequest request ,String d) {
				Emp emp = (Emp) request.getSession().getAttribute("emp");
				d=emp.getEmpName();
				ts.addtkjl(to,d);
				return " redirect:tkjl?pageNum=1&pasgeSize=7";
			}
			//模糊查询
			@RequestMapping("tk-sjmh")
			@ResponseBody
			public Map<String,Object>selectsj(Integer pageNum,Integer pasgeSize,String rq){
				//分页
				Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
				//查询数据
				JSONArray selectsj=ts.selectsj("%"+rq+"%");
				//创建Map集合
				return this.yy(selectsj, page);
				
			}
}
